package com.estock.common.util;

import org.apache.commons.lang.StringUtils;

import com.estock.common.model.security.enums.StockType;

public class StockUtil {
	
	public static final int TYPE_SH = 1;
	public static final int TYPE_SZ = 2;
	public static final int TYPE_SH_INDEX = 3;
	public static final int TYPE_SZ_INDEX = 4;
	
	public static final String TNAME_SH = "沪市";
	
	
	public static int getStockTypeByCode(String code) {
		if (code == null || StringUtil.isEmpty(code)) {
			throw new RuntimeException("Error: empty stock code!");
		}
		if (code.length() != 6) {
			throw new RuntimeException("Error: stock code must be 6 bits!");
		}
		
		if (StringUtils.startsWith(code, "6")) {
			return StockType.SH.getType();
		}
		if (StringUtils.startsWith(code, "0") || StringUtils.startsWith(code, "3")) {
			return StockType.SZ.getType();
		}
		
		throw new RuntimeException("Error: stock code must be started with 6, 3 and 0!");
	}
	
	public static boolean isAStock(String code) {
		return StringUtils.startsWith(code, "6") || 
				StringUtils.startsWith(code, "0") || 
				StringUtils.startsWith(code, "3");
	}
	
	
}
